package com.shangxian.giveithome.aspect;

import com.shangxian.giveithome.utils.RedisUtils;
import lombok.extern.log4j.Log4j2;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;


@Aspect
@Component
@Log4j2
public class InterFaceAspect {

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private RedisUtils redisUtils;

    /**
     * 在执行方法前检查登录态   //TODO 可优化
     *
     * @param joinPoint
     * @return
     * @throws Throwable
     */
    @Before(value = "@annotation(com.shangxian.giveithome.annoaction.CheckLoginStatus)")
    public void CheckLoginStatus(JoinPoint joinPoint) throws Throwable {
        System.out.println(joinPoint);
        redisUtils.checkStatus(request);
    }
}
